package haemers.reflection.tests 
{
	import flash.display.CapsStyle;
	import flash.display.MovieClip;
	import flash.utils.Dictionary;
	import flash.utils.getDefinitionByName;
	import flash.utils.getQualifiedClassName;
	import haemers.reflection.data.vo.TypeVO;
	import nl.haemers.data.reflection.IAccessors;
	import nl.haemers.data.reflection.IMetadatas;
	import nl.haemers.data.reflection.IMethod;
	import nl.haemers.data.reflection.IProperty;
	import nl.haemers.data.reflection.IVariables;
	import nl.haemers.data.reflection.Type;
	import org.flexunit.Assert;
	/**
	 * ...
	 * @author Jonathan
	 */
	public class TypeTest 
	{
		private var _type:Type;
		
		/** Public methods **/
		[Before]
		public function setup() : void
		{
			_type = new Type(1);
			_type.init(TypeVO);
		}
		
		[Test]
		public function test() : void
		{
			Assert.assertEquals("Object", _type.base);
			Assert.assertEquals("haemers.reflection.data.vo::TypeVO", _type.className);
			
			Assert.assertTrue(_type.instance is TypeVO);
			
			Assert.assertNotNull(_type.metadatas);
			Assert.assertTrue(_type.metadatas is IMetadatas);
			
			Assert.assertTrue(_type.createInstance() is TypeVO);
			
			Assert.assertTrue(_type.hasParent());
			
		}
		
		[Test]
		public function testSerialize() : void
		{
			Assert.assertEquals("test_type", _type.name);
			Assert.assertFalse(_type.name.indexOf("TypeVO") > -1);
		}
		
		[Test]
		public function testMethods() : void
		{
			Assert.assertTrue(_type.getMethod("addCollection") is IMethod);
			Assert.assertEquals(_type.getMethod("addCollection"), _type.getMethodWithParam("name"), _type.getMethodWithParam("collection"));
			Assert.assertTrue(_type.hasMethod("addCollection"));
			Assert.assertFalse(_type.hasMethod("getId"));
			
			Assert.assertTrue(_type.hasMethodWithParam("name"));
			Assert.assertFalse(_type.hasMethodWithParam("id"));
		}
		
		[Test]
		public function testCollection() : void
		{
			var vectorType:Type = new Type(0);
			vectorType.init(getDefinitionByName(getQualifiedClassName(new Vector.<MovieClip>())) as Class);
			
			Assert.assertTrue(vectorType.collectionItemType is Type);
			Assert.assertTrue(vectorType.createCollectionItem() is MovieClip);
		}
		
		[Test]
		public function testProperties() : void
		{
			Assert.assertTrue(_type.getProperties() is Dictionary);
			Assert.assertTrue(_type.getProperty("firstName") is IProperty);
			Assert.assertTrue(_type.hasProperty("firstName"));
			
			Assert.assertTrue(_type.getProperty("key") is IProperty);
			Assert.assertTrue(_type.hasProperty("key"));
		}
		
		[Test]
		public function testVariables() : void
		{
			Assert.assertTrue(_type.variables is IVariables);
		}
		
		[Test]
		public function testAccessors() : void
		{
			Assert.assertTrue(_type.accessors is IAccessors);
		}
		
		[Test]
		public function testDynamic() : void
		{
			var _dynamicType:Type = new Type(0);
			_dynamicType.init(MovieClip);
			
			Assert.assertFalse(_type.isDynamic);
			Assert.assertTrue(_dynamicType.isDynamic);
		}
		
		[Test]
		public function testStatic() : void
		{
			/*
			 * NOTE: No Static classes in AS3?
			 **/ 
			//var _staticType:Type = new Type(0);
			//_staticType.init();
			
			Assert.assertFalse(_type.isStatic);
		}
		
		[Test]
		public function testFinal() : void
		{
			var finalType:Type = new Type(0);
			finalType.init(CapsStyle);
			
			Assert.assertFalse(_type.isFinal);
			Assert.assertTrue(finalType.isFinal);
		}
		
		[After]
		public function teardown() : void
		{
			_type = null;
		}
		/** Getters & Setters **/
		
		/** Protected methods **/
		
		/** Private methods **/
	}

}